import axios from "axios";
import { $envApi } from "../common/utils";

export const Service = axios.create({
    timeout: 80000, //延迟时间
    baseURL: $envApi(),
})

// 请求拦截
Service.interceptors.request.use(
    (config: any) => {
        // 可以在发送请求之前做些事情
        // 比如请求参数的处理、在headers中携带token等等
        config.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';
        config.headers['Pragma'] = 'no-cache';
        config.headers['Expires'] = '0';
        const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOjEsImV4cCI6MTY4Mzk0Njg5OH0.NLsZfOD1PjZtuu0oyFOBpobT3fSZvQPOmKjUJv5QokY";
        if (token) {
            config.headers.Authorization = `Bearer ${token}`;
        }

        return config;
    },
    (err) => {
        // 处理请求错误
        Promise.reject(err);
    }
);

// 响应拦截
Service.interceptors.response.use(res => {
    
    return res.data
}, err => {
    console.log(err)
})